package com.woniuxy.factory;

/*
* 三代工厂
* */

import com.woniuxy.entity.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/*动态创建对应的类*/
public class ThirdFactory {

    public Person doPerson() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        //解析properties文件
        Properties properties = new Properties();
        //二阶段输入流通过上面读取
        InputStream resourceAsStream = ThirdFactory.class.getResourceAsStream("doPerson.properties");

        String personName = "";
        Person person = null;
        try {
            //加载读取我们的配置文件
            properties.load(resourceAsStream);
            personName = properties.getProperty("person");

            //通过从配置文件中拿到的全限定类类名，来创建对象
            person = (Person) Class.forName(personName).newInstance();
            resourceAsStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return person;
    }
}
